<?php
/**
 * Created by PhpStorm.
 * User: kcross
 * Date: 20-6-26
 * Time: 下午5:52
 */

namespace App\Admin\Actions;

use App\Models\Circle;
use App\Models\Send;
use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;

class QueueBatchAction extends BatchAction {

    public $name = '批量添加到发送队列';

    public function handle(Collection $collection)
    {
        if (!empty($collection)) {
            $model = $collection[0];
            /** @var Send|Circle $class */
            $class = get_class($model);
            foreach ($collection as $model) {
                $class::addQueue($model->id);
            }
        }

        return $this->response()->success('Success message...')->refresh();
    }
}